cmake_minimum_required(VERSION 3.16)
project(log_mcap_example)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(mcap REQUIRED)
find_package(Protobuf REQUIRED)

# Use pkg-config to find lz4 and zstd, as find_package is not reliable
# across all systems for these libraries.
find_package(PkgConfig REQUIRED)
pkg_check_modules(LZ4 REQUIRED liblz4)
pkg_check_modules(ZSTD REQUIRED libzstd)

add_executable(log_mcap log_mcap.cpp)

# 生成protobuf C++文件
add_custom_command(
    OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/plannintg_mcap_debug.pb.cc ${CMAKE_CURRENT_SOURCE_DIR}/plannintg_mcap_debug.pb.h
    COMMAND ${Protobuf_PROTOC_EXECUTABLE}
    ARGS --cpp_out ${CMAKE_CURRENT_SOURCE_DIR} --proto_path ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/plannintg_mcap_debug.proto
    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/plannintg_mcap_debug.proto
    COMMENT "Generating protobuf files"
)

# 添加生成的源文件到目标
target_sources(log_mcap PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/plannintg_mcap_debug.pb.cc)

# Instead of using the modern target, link against the libraries and include
# directories found by find_package directly. This is more robust if the
# mcap-config.cmake file does not correctly define the mcap::mcap target.
target_include_directories(log_mcap PRIVATE ${mcap_INCLUDE_DIRS})
target_include_directories(log_mcap PRIVATE ${Protobuf_INCLUDE_DIRS})
target_include_directories(log_mcap PRIVATE ${LZ4_INCLUDE_DIRS} ${ZSTD_INCLUDE_DIRS})
target_include_directories(log_mcap PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(log_mcap PRIVATE ${mcap_LIBRARIES} ${Protobuf_LIBRARIES} ${LZ4_LIBRARIES} ${ZSTD_LIBRARIES})
